home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWViews / FWButton.h < prev    next >
Encoding:
Text File  |  1996-09-17  |  3.8 KB  |  146 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWButton.h
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWBUTTON_H
  11. #define FWBUTTON_H
  12.  
  13. // ----- Foundation Includes -----
  14.  
  15. #ifndef FWNOTIFN_H
  16. #include "FWNotifn.h"
  17. #endif
  18.  
  19. #ifndef FWNOTIFR_H
  20. #include "FWNotifr.h"
  21. #endif
  22.  
  23. // ----- OS Includes -----
  24.  
  25. #ifndef FWFONT_H
  26. #include "FWFont.h"
  27. #endif
  28.  
  29. // ----- Framewrk Includes -----
  30.  
  31. #ifndef FWCONTRH_H
  32. #include "FWContrH.h"
  33. #endif
  34.  
  35. #ifndef FWCONTRL_H
  36. #include "FWContrl.h"
  37. #endif
  38.  
  39. #ifndef FWVIEWS_K
  40. #include "FWViews.k"
  41. #endif
  42.  
  43. //========================================================================================
  44. //    Forward class declarations
  45. //========================================================================================
  46.  
  47. class FW_CViewContext;
  48.  
  49. //========================================================================================
  50. //    Button kinds
  51. //========================================================================================
  52.  
  53. typedef unsigned long  FW_ButtonKind;
  54.  
  55. // Button kind constants are defined in <FWViews.k> in order to be used in resource files:
  56. //     FW_kPushButton, FW_kRadioButton, FW_kCheckButton, FW_kDefaultPushButton    
  57.  
  58. //========================================================================================
  59. //    CLASS FW_CButton
  60. //========================================================================================
  61.  
  62. class FW_CButton : public FW_CNativeControl
  63. {
  64. // ----- Initialization/destruction
  65. public:
  66.     FW_DECLARE_CLASS
  67.     FW_DECLARE_AUTO(FW_CButton)
  68.  
  69.     // one-step initialization constructor
  70.     FW_CButton(Environment* ev, 
  71.                 FW_CSuperView* container, 
  72.                 const FW_CRect& bounds,
  73.                 ODID viewID,
  74.                 FW_ButtonKind kind,
  75.                 const FW_CString& label,
  76.                 const FW_CFont& font = FW_kSystemFont,
  77.                  FW_Message msg = FW_kButtonPressedMsg,
  78.                  FW_ControlValue value = 0);
  79.                 
  80.     // two-step initialization constructor
  81.     FW_CButton(Environment* ev);
  82.  
  83.     virtual ~FW_CButton();
  84.     
  85. // ----- Getters/Setters -----
  86.     FW_ButtonKind        GetButtonKind(Environment* ev) const;
  87.     void                SetButtonKind(Environment* ev, FW_ButtonKind kind);
  88.     
  89.     void                SetState(Environment* ev, FW_Boolean on);
  90.     FW_Boolean            GetState(Environment* ev) const;
  91.     
  92. // ----- Control API
  93.     virtual void        ControlClicked(Environment *ev, FW_ControlValue value, ODFacet* facet);
  94.  
  95. // ----- View API
  96.     virtual void         Draw(Environment* ev, ODFacet* facet, ODShape* invalidShape);
  97.     
  98. // ----- Archiving -----
  99.     static void*        Create(FW_CReadableStream& stream, FW_ClassTypeConstant type);
  100.     static void            Destroy(void* object, FW_ClassTypeConstant type);
  101.     virtual void        Flatten(Environment* ev, FW_CWritableStream& stream) const;
  102.     virtual void        InitializeFromStream(Environment* ev, FW_CReadableStream& stream);
  103.     
  104. // ----- Utilities
  105.     void                SimulateButtonPressed(Environment* ev);    
  106.  
  107. protected:
  108.     // ----- Internal use only
  109.     virtual FW_Boolean     PrivSetValue(Environment* ev, FW_ControlValue value, ODFacet* facet);
  110.  
  111. private:
  112.     void Initialize(Environment* ev, 
  113.                 FW_ButtonKind kind,
  114.                 const FW_CString& label,
  115.                 const FW_CFont& font);
  116.  
  117. #ifdef FW_BUILD_MAC
  118.     short                MacGetProcID(); 
  119. #endif
  120.  
  121. // ----- Data
  122. private:
  123.     FW_ButtonKind                fKind;
  124. };
  125.  
  126. //========================================================================================
  127. // Inlines
  128. //========================================================================================
  129.  
  130. inline FW_ButtonKind    FW_CButton::GetButtonKind(Environment*) const
  131. {
  132.     return fKind;
  133. }
  134.  
  135. inline FW_Boolean FW_CButton::GetState(Environment* ev) const
  136. {
  137.     return (GetValue(ev) == 0) ? false : true;
  138. }
  139.  
  140. inline void FW_CButton::SetState(Environment* ev, FW_Boolean on) 
  141. {
  142.     SetValue(ev, on ? 1 : 0);
  143. }
  144.  
  145. #endif
  146.